﻿/*===================================================================================
	TASK 6:                                                                  {Loop's}
	Write a program that, for a given two integer numbers N and X, calculates the sum
    S = 1 + 1!/X + 2!/X2 + … + N!/X^N
===================================================================================*/

using System;

class CalculateSum
{
    static void Main()
    {
        Console.Write("Enter N=");
        decimal n = decimal.Parse(Console.ReadLine());
        Console.Write("Enter X=");
        decimal x = decimal.Parse(Console.ReadLine());

        decimal supX = 1;
        decimal fac = 1;
        decimal sum = 1;

        for (int i = 1; i <=n; i++)
        {
            supX *= x;
            fac *= i;
            sum = sum + (fac / supX);
        }

        Console.WriteLine(sum);


        //Console.Write("Enter N = ");
        //int n = int.Parse(Console.ReadLine());
        //Console.Write("Enter X = ");
        //int x = int.Parse(Console.ReadLine());
        //if ((n < 0) || (x <= 0))
        //{
        //    Console.WriteLine("Enter new values for N and X");
        //    return;
        //}
           
        //decimal suma=1;
        //decimal factoriel = 1;
        //decimal stepen = 1;
        //for (int i = 1; i <= n; i++)
        //{
        //    stepen *= x;
        //    factoriel *= i;
        //    suma += (factoriel/ stepen);
        //}
               
        //Console.WriteLine("Suma(n!)/(x^n)={0}", suma);
    }
}

